const utils = {
    getType: function(param) {
        const toString = Object.prototype.toString;
        return toString.call(param).slice(8, -1);
    },
    isEmpty: function (obj) {
        if (typeof obj === "undefined" || obj === null || obj === "") {
            return true;
        }
        return false;
    },
    delHtmlTag(str){
        return str.replace(/<[^>]+>/g,"");//去掉所有的html标记
    },
    isPhoneNum(phone) {
        const reg = /^1[34578]\d{9}$/;
        if(reg.test(phone)) {
            return true;
        }
        return false;
    },
    formatPrice(price) {
        if(!price) {
            price = 0;
        }
        price = Math.round(parseFloat(price) * 100) / 100;
        const xsd = price.toString().split(".");
        if (xsd.length == 1) {
            price = price.toString() + ".00";
          return price;
        }
        if (xsd.length > 1) {
          if (xsd[1].length < 2) {
            price = price.toString() + "0";
          }
          return price;
        }
    },
    format: function(date, type) {
        if(!type) return;
        if(!(date instanceof Date)) {
            if(/\d{4}(-|\/)\d{1,2}(-|\/)\d{1,2}/.test(date)) {
                date = new Date(date);
            } else {
                date = new Date(Number(date));
            }
        }
        const year = date.getFullYear()
        let month = date.getMonth() + 1
        if(month < 10) {
            month = '0' + month;
        }
        let day = date.getDate()
        if(day < 10) {
            day = '0' + day;
        }
        // const hour = date.getHours()
        // const minute = date.getMinutes()
        // const second = date.getSeconds()
        const newDate = [];
        if(/(y+)/.test(type)) {
            newDate.push(year);
        }
        if(/(m+)/.test(type)) {
            newDate.push(month);
        }
        if(/(d+)/.test(type)) {
            newDate.push(day);
        }
        return newDate.join('-');
        
    }

}
export default utils;